package com.by.config;

import com.by.ex.LazyExchange;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ServivE
 * @version 0.1
 * @className RabbitConfig
 * @description
 * @date 2024/10/23 13:40
 * @since jdk17
 */
@Configuration
public class RabbitConfig {
    @Bean
    public Queue queue() {
        return new Queue("lazy-queue");
    }


   /* @Bean
    public CustomExchange customExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange("lazyEx", "x-delayed-message", true, false, map);
    }*/
    /*@Bean
    public Binding binding(Queue queue, CustomExchange customExchange) {
        return BindingBuilder.bind(queue).to(customExchange).with("lazy").noargs();
    }*/

    /**
     * 自定义延迟交换器
     *
     * @return
     */
    @Bean
    public LazyExchange lazyExchange() {
        return new LazyExchange("lazyEx");
    }

    @Bean
    public Binding binding(Queue queue, LazyExchange lazyExchange) {
        return BindingBuilder.bind(queue).to(lazyExchange).with("lazy").noargs();
    }

}
